<template>
  <div>
    <input v-model="newTodoTitle" placeholder="添加新的待办事项" />
    <button @click="addTodo">添加</button>
    <ul>
      <li v-for="(todo, index) in todos" :key="index">
        <todo-item
          :title="todo.title"
          :completed="todo.completed"
          @update:completed="updateTodoCompleted(index, $event)"
          @remove-todo="removeTodo(index)"
        />
      </li>
    </ul>
  </div>
</template>

<script>
import TodoItem from './TodoItem.vue';

export default {
  data() {
    return {
      todos: [],
      newTodoTitle: ''
    };
  },
  components: {
    TodoItem
  },
  methods: {
    addTodo() {
      if (this.newTodoTitle.trim()) {
        this.todos.push({ title: this.newTodoTitle, completed: false });
        this.newTodoTitle = '';
      }
    },
    removeTodo(index) {
      this.todos.splice(index, 1);
    },
    updateTodoCompleted(index, completed) {
      this.todos[index].completed = completed;
    }
  }
}
</script>

<!-- 你可能需要根据你的图片样式进行CSS样式调整 -->
<style scoped>
/* 根据图片提供的样式，这里只是一个基本的样式示例 */
button {
  margin: 10px 0;
  padding: 5px 10px;
  background-color: #5cb85c;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #449d44;
}

.completed {
  text-decoration: line-through;
}
</style>
